﻿Imports HYQueryGrid
Imports System.Windows.Forms

Public Class dlgCommonSelect
    Private mcollSelectedValue As Collection
    Private mstrFieldName As String

    Public Function ShowOpen(ByVal dt As DataTable, ByVal title As String, ByVal fieldName As String) As Collection
        Me.Text = title
        Me.Grid1.DataSource = dt
        mcollSelectedValue = New Collection
        mstrFieldName = fieldName

        Me.ShowDialog()
        Return mcollSelectedValue
    End Function


    Private Sub Confirm()
        For Each row As DataGridViewRow In Grid1.SelectedRows
            mcollSelectedValue.Add(row.Cells(mstrFieldName).Value)
        Next
        Me.Close()
    End Sub

    Private Sub ToolStrip1_ItemClicked(sender As Object, e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked
        Select Case e.ClickedItem.Text
            Case "选择"
                Confirm()
            Case "关闭"
                Me.Close()
        End Select
    End Sub

    Private Sub Grid1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Grid1.KeyDown
        Select Case e.KeyCode
            Case Keys.Return
                Confirm()
        End Select
    End Sub

    Private Sub Grid1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Grid1.KeyUp
        Select Case e.KeyCode
            Case Keys.Escape
                Me.Close()
        End Select
    End Sub

    Private Sub Grid1_RowDoubleClick(rowIndex As Integer) Handles Grid1.RowDoubleClick
        Grid1.Rows(rowIndex).Selected = True
        Confirm()
    End Sub
End Class